package com.jt.controller;

import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

//    @GetMapping("/findItemCatList/{level}")
//    public SysResult  findItemCatList(@PathVariable Integer level){
//        List<ItemCat> itemCatList= itemCatService.findItemCatList(level);
//        return  SysResult.success( itemCatList);
//
//    }
//

    @GetMapping("/findItemCatList/{level}")
    public SysResult  findItemCatList(@PathVariable Integer level){
        List<ItemCat> itemCatList= itemCatService.findItemCatList(level);
        return  SysResult.success( itemCatList);

    }

    /*修改状态*/
    @PutMapping("/status/{id}/{status}")
    public SysResult update( ItemCat itemCat){
        itemCatService.updateItem(itemCat);
        return SysResult.success();
    }

    /*商品新增*/
    @PostMapping("/saveItemCat")
    @Transactional
    public SysResult   saveItemCat(@RequestBody ItemCat itemCat){
        System.out.println( itemCat);
        itemCatService.saveItemCat(itemCat);
        return SysResult.success();
    }

    /*删除*/
    @DeleteMapping("/deleteItemCat")
    @Transactional
    public SysResult delete( Integer id, Integer level){
        itemCatService.deleteItemCat(id,level);
        return SysResult.success();

    }


    /*修改分类*/
//    public  SysResult update
}
